Skip to content

Ensure files are always closed after use#5346

Open
aakallam wants to merge 1 commit into
masterfrom
push-rktqpxtnxyxo
Open

Ensure files are always closed after use#5346
aakallam wants to merge 1 commit into
masterfrom
push-rktqpxtnxyxo

Conversation

@aakallam

@aakallam aakallam commented Jul 1, 2026

Copy link
Copy Markdown
Collaborator

This is a follow up to #5342 that refactors a bunch of file I/O to use with statements to ensure that the file handles are always closed. Closing file handles is especially important on Windows because only one file object can point at a file at one time.

To make a few complex file opening cases work, this PR adds a couple new path variables to simplify the refactoring but otherwise does not introduce or change any logic.

@aakallam aakallam force-pushed the push-rktqpxtnxyxo branch 5 times, most recently from dd606d1 to 79d5a0e Compare July 1, 2026 20:16
@aakallam aakallam force-pushed the push-rktqpxtnxyxo branch from 79d5a0e to 46a8e8c Compare July 9, 2026 17:04
@aakallam aakallam requested a review from dylanjew July 9, 2026 17:21
@aakallam aakallam marked this pull request as ready for review July 9, 2026 17:21
@aakallam aakallam requested a review from a team as a code owner July 9, 2026 17:21

@dylanjew dylanjew left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thanks!

finally:
# Don't need the archive after writing testcase to blobstore.
if zip_path:
shell.remove_file(zip_path)

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there a similar way we can handle file clean up?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you mean for the testcase files or something else?

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I thought it was strange that we're manually calling remove_file(zip_path) in a couple places but I'm not sure of a way around that.

either way cleaning up the file usage LGTM

finally:
# Don't need the archive after writing testcase to blobstore.
if zip_path:
shell.remove_file(zip_path)

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I thought it was strange that we're manually calling remove_file(zip_path) in a couple places but I'm not sure of a way around that.

either way cleaning up the file usage LGTM

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants